package cn.jorian.framework.service.impl;

import cn.jorian.framework.bean.PageParam;
import cn.jorian.framework.bean.ResponseResult;
import cn.jorian.framework.entity.User;
import cn.jorian.framework.mapper.UserMapper;
import cn.jorian.framework.service.UserService;
import cn.jorian.framework.util.GsonUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.reflect.TypeToken;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【user(用户表)】的数据库操作Service实现
* @createDate 2024-05-22 13:51:07
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService {

    @Override
    public ResponseResult<IPage<User>> getListPage(String json) {
        //请求参数
        PageParam<User> pageParam = GsonUtil.fromJson(json, new TypeToken<PageParam<User>>(){});
        if (pageParam == null) {
            return new ResponseResult<>("false", "-1", "参数错误");
        }
        //分页
        Page<User> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", pageParam.getParam().getUsername());
        IPage<User> iPage = page(page, queryWrapper);

        return new ResponseResult<>("true", "200", "成功", iPage);
    }
}




